package leilib.ir.dns;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class CrawlDateTest {

	CrawlDate date;

	@Before
	public void setUp() throws Exception {
		date = new CrawlDate(2009, 4, 30);
		// System.out.println(this.date.getLastModifyYear()+
		// ","+this.date.getLastModifyMonth()+
		// ","+this.date.getLastModifyDate());
		// System.out.println("2009.4.30:"+this.date.toDays());
	}

	@Test
	public void testDeltaInDays() {
		CrawlDate another = new CrawlDate(2008, 4, 30);
		int delta = CrawlDate.deltaInDays(another, date);
		assertEquals(365, delta, 0.1);

		another = new CrawlDate(2009, 3, 30);
		delta = CrawlDate.deltaInDays(another, date);
		assertEquals(30, delta, 0.1);

		another = new CrawlDate(2009, 4, 29);
		delta = CrawlDate.deltaInDays(another, date);
		assertEquals(1, delta, 0.1);
	}

	@Test
	public void testModify() {
		int year = 2009;
		int month = 5;
		int date = 20;

		// System.out.println("2009.5.20:"+new
		// CrawlDate(year,month,date).toDays());
		this.date.modify(year, month, date);

		assertEquals(year, this.date.getLastModifyYear(), 0.5);
		assertEquals(month, this.date.getLastModifyMonth(), 0.5);
		assertEquals(date, this.date.getLastModifyDate(), 0.5);
	}

	@Test
	public void testIsAfter() {
		CrawlDate after = new CrawlDate(2009, 4, 31);
		assertTrue(after.isAfter(this.date));

		CrawlDate fore = new CrawlDate(2009, 4, 29);
		assertFalse(fore.isAfter(this.date));
	}

}
